<template>
  <div>

    <Panel title="" useBack>
         <ModifyForm
        slot="body"
        :editColumn="editColumn"
        :temporaryData='temporaryData'
        labelWidth="150px"
        :updateData="updateData"
      >
        <p
          slot="title"
        ></p>

      </ModifyForm>
    </Panel>
  </div>
</template>
<script>
import Panel from "@/components/Panel";
import ModifyForm from "@/components/ModifyForm";
import ModalPanel from "@/components/ModalPanel";
import FileUpload from '@/components/FileUpload';
import request from "@/tools/request";
import { dateFormat } from "@/tools/time";

export default {
  name:'thirdApiInfo',
  components: {
    FileUpload,
    Panel,
    ModalPanel,
    ModifyForm
  },
  data() {
    return {
     configValue:"",
      editorOption: {},
      typeList: [],
      temporaryData: {},
      appointmentTime: null,
      appointmentTimePost: null,
      editColumn: [
        {
          name: "接口名称",
          prop: "name",
          type: "text",
          width:12,
          required: true
        },
        {
          name: "第三方公司",
          prop: "companyId",
          type: "select",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': '','name': "请选择公司"}],
          width:12,
          required: true
        },
        {
          name: "运营商标识",
          width: 12,
          prop: "operatorId",
          type: "text",
          required: false
        },
         {
          name: "主动通知url",
          prop: "notifyUrl",
          type: "text",
          width:12,
          required: true
        },
        {
          name: "通知用AES加解密向量",
          prop: "notifyAesIv",
          type: "text",
          width:12,
          required: true
        },
        {
          name: "知用AES加解密秘钥",
          prop: "notifyAesKey",
          type: "text",
          width:12,
          required: true
        },
        {
          name: "通知用运营商标识",
          prop: "notifyOperatorId",
          type: "text",
          width:12,
          required: true
        },
        {
          name: "通知用运营商秘钥",
          prop: "notifyOperatorSecret",
          type: "text",
          width:12,
          required: true
        },
        {
          name: "通知用签名秘钥",
          prop: "notifySignKey",
          type: "text",
          width:12,
          required: true
        },
      ],
    };
  },
  computed: {
 

  },
  methods: {
   async updateData(values) {
     const {id, name, companyId, operatorId, notifyUrl, notifyAesIv, notifyAesKey, notifyOperatorId, notifyOperatorSecret, notifySignKey } = values
     let url = id ? "/third/api/update": "/third/api/add"
     let msg = id ? "编辑成功" : "添加成功"
     let res = await request({
       url: url,
       method: "POST",
       data:{id, name, companyId, operatorId, notifyUrl, notifyAesIv, notifyAesKey, notifyOperatorId, notifyOperatorSecret, notifySignKey }
     })
     if(res.code !==0) return
      this.$message.success(msg)
      this.$router.go(-1)
    },
    async fetchData(id){
      let { api } = await request({
        url: "/third/api/info/"+id,
        method: "GET",
        data: {}
      });
      this.temporaryData = api
    },
    //站点
    async getCompany(){
      let { list } = await request({
      url: "/third/company/select",
      method: "POST",
      data: {}
      });
      this.editColumn[1].optionList = list
    }
  },
  created() {
    this.getCompany()
    if(this.$route.query.id)
      this.fetchData(this.$route.query.id)
  }
};
</script>

<style lang='scss' >

</style>